package com.shqcjd.preinstallglass.ui.activity.input;

import android.app.Activity;
import android.content.Intent;
import android.widget.Button;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.shqcjd.preinstallglass.R;
import com.shqcjd.preinstallglass.ui.base.BaseActivity;
import com.shqcjd.preinstallglass.ui.base.BasePresenter;

import butterknife.BindView;

public class VoiceInputActivity extends BaseActivity {
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.btn_clean)
    Button btnClean;
    @BindView(R.id.btn_back)
    Button btnBack;
    @BindView(R.id.btn_confirm)
    Button btnConfirm;

    private StringBuffer stringBuffer = new StringBuffer();
    private Activity mActivity;
    private String str;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_voice_input;
    }

    @Override
    public boolean isVoiceType() {
        return true;
    }

    @Override
    public void initView() {
        super.initView();
        mActivity = this;
        str = (getIntent().getStringExtra("str")==null?"":getIntent().getStringExtra("str"));
        stringBuffer.append(str);
        tvContent.setText(stringBuffer);
    }

    @Override
    protected void onVoiceResult(String result) {
        Logger.i("识别结果:"+result);
        if (result.contains("接受")) {
            Intent it = new Intent();
            it.putExtra("input_key", stringBuffer.toString().trim());
            mActivity.setResult(RESULT_OK, it);
            mActivity.finish();

        } else if (result.contains("退格")) {
            if (!stringBuffer.toString().equals("")) {
                stringBuffer.deleteCharAt(stringBuffer.length() - 1);
                tvContent.setText(stringBuffer.toString());
            }
        } else if (result.contains("清除")) {
            stringBuffer.delete(0, stringBuffer.length());
            tvContent.setText(stringBuffer.toString());
        } else {
            if (!result.contains("。")) {
                stringBuffer.append(result);
                tvContent.setText(stringBuffer.toString());
            }
        }
    }
}
